<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>时间提醒</title>
	</head>
	<body>
		<script>
			Notification.requestPermission(function (permission) {
				console.log(
					'用户是否允许通知： ',
					permission === 'granted' ? '允许' : '拒绝'
				);
				if (permission === 'granted') {
					let count = 0;
					setInterval(() => {
						showNoticification('提醒喝水小助手', '喝水喝水该喝水了~');
						count++;
						if (count >= 2) {
							showNoticification('提醒走动小助手', '你已经做了一个小时了~');
							count = 0;
						}
					}, 20 * 60 * 1000);
					function showNoticification(theBody, theTitle) {
						var options = {
							body: theBody,
						};
						var n = new Notification(theTitle, options);
					}
				}
			});
		</script>
	</body>
</html>
